package cn.edu.scnu.movies.controller;

import cn.edu.scnu.movies.entity.Result;
import cn.edu.scnu.movies.entity.movies;
import cn.edu.scnu.movies.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api")
public class IndexController {

    @Autowired
    private IndexService indexService;

    /**
     * 根据演员姓名查询其主演的电影
     */
    @GetMapping(value = "/person/actor", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result actor(@RequestParam String name){
        List<movies> list = indexService.actor(name);
        if(list == null || list.isEmpty()){
            return Result.error("没有这个演员");
        }
        return Result.success(list);
    }

    /**
     * 根据导演姓名查询其执导的电影
     */
    @GetMapping("/person/director")
    public Result findMoviesByDirector(@RequestParam String name){
        List<movies> list = indexService.findMoviesByDirector(name);
        if(list == null || list.isEmpty()){
            return Result.error("没有这个导演");
        }
        return Result.success(list);
    }
}
